package org.smart4j.framework.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URLEncoder;

/**
 *
 * 编码与解码操作工具类
 *
 * @author: Mr.Zhou
 * @create: 2018-10-24 16:34
 **/
public final class CodecUtil {

    private static final Logger LOGGER= LoggerFactory.getLogger(CodecUtil.class);

    /**
     * 将 URL编码
     * @return
     */
    public static String encodeURL(String source){
        String target;
        try {
            target= URLEncoder.encode(source,"UTF-8");
        }catch (Exception e){
            LOGGER.error("encode url failure",e);
            throw new RuntimeException(e);
        }
        return target;
    }

    /**
     * 将 URL解码
     * @return
     */
    public static String decodeURL(String source){
        String target;
        try {
            target= URLEncoder.encode(source,"UTF-8");
        }catch (Exception e){
            LOGGER.error("encode url failure",e);
            throw new RuntimeException(e);
        }
        return target;
    }


}
